<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/lib/layui-v2.7.6/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">编号</label>
                            <div class="layui-input-inline">
                                <input type="text" name="serial_num" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">微信昵称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="vx" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">订单状态</label>
                            <div class="layui-input-inline">
                                <select name="order_status" lay-verify="" lay-search="">
                                    <option value=""></option>
                                    <option value="0">未处理</option>
                                    <option value="1">待配送</option>
                                    <option value="2">已完成</option>
                                    <option value="3">退款</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">订单类型</label>
                            <div class="layui-input-inline">
                                <select name="order_type" lay-verify="" lay-search="">
                                    <option value=""></option>
                                    <option value="0">微信</option>
                                    <option value="1">门店</option>
                                    <option value="2">美团</option>
                                    <option value="3">饿了么</option>
                                    <option value="4">抖音</option>
                                    <option value="5">高德</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">收货地址</label>
                            <div class="layui-input-inline">
                                <input type="text" name="address" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">配送时间范围</label>
                            <div class="layui-input-inline">
                                <input type="text" name="send_time_area" class="layui-input" id="test10" placeholder=" - ">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">年份</label>
                            <div class="layui-input-inline">
                                <select name="year" id="year"  lay-search="">
                                    <option value=""></option>
                                    <option value="2022">2022</option>
                                    <option value="2023" selected>2023</option>
                                    <option value="2024">2024</option>
                                    <option value="2025">2025</option>
                                    <option value="2026">2026</option>
                                    <option value="2027">2027</option>
                                    <option value="2028">2028</option>
                                    <option value="2029">2029</option>
                                    <option value="2030">2030</option>
                                    <option value="2031">2031</option>
                                    <option value="2032">2032</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">分类</label>
                            <div class="layui-input-inline">
                                <select name="holiday_type" id="holiday_type" lay-verify="" lay-search="">
                                    <option value=""></option>
                                    <option value="0">其他</option>
                                    <option value="1" selected>情人节</option>
                                    <option value="2">七夕</option>
                                    <option value="3">520</option>
                                    <option value="4">妇女节</option>
                                    <option value="5">教师节</option>
                                    <option value="6">母亲节</option>
                                    <option value="7">圣诞节</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn  layui-btn-warm layui-btn-sm data-add-btn" lay-event="add"> 添加 </button>
<!--                <button class="layui-btn layui-btn-normal layui-btn-sm data-edit-btn" lay-event="edit"> 编辑 </button>-->
<!--                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除 </button>-->
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
<!--            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>-->
        </script>

    </div>
</div>
<style>
    .detailView {
        padding: 10px;
        background-color: #e2eaf0;
        color: #0F0F0F;
        white-space: pre-line;
    }
    .detailTitle {
        font-size: 20px;
        font-weight: 500;
        line-height: 22px;
        height: 22px;
        margin-bottom: 10px;
    }
    .detailAuthor {
        font-size: 12px;
        color: #65645F;
        margin-bottom: 6px;
    }
    .detailContent {

    }
</style>
<script type="text/html" id="expandAll">
        <div class="layui-row detailView" >
            <div class="layui-col-xs1"  style="width:6.33333%;margin-right: 5px;">
                <img height="110px" src="/img{{d.img.file_path}}/{{d.img.file_name}}" alt="" onclick="showimg(this)">
            </div>
            <div class="layui-col-xs3">
                    <div class="detailAuthor">花束：{{d.flower_name}}</div>
                    <div class="detailContent">客户：{{d.name}} {{d.mobile}} {{d.address}}</div>
                    {{#  if(d.card == 1){ }}
                        <div class="detailContent">卡片： {{d.card_content}}</div>
                    {{#  } }}
                    <div class="detailContent">微信： {{d.vx}}</div>
                    <div class="detailContent">时间： {{d.send_time}}</div>
                    <div class="detailContent">编号： <b>{{d.serial_num}}</b></div>
            </div>
            <div class="layui-col-xs1">
                {{#  if(d.order_status == 0){ }}
                <div class="detailContent" style="margin-bottom: 2px"><a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="deal" data="{{d.id}}" >排单</a></div>
                {{#  } }}
                {{#  if(d.order_status < 2){ }}
                <div class="detailContent" style="margin-bottom: 2px"><a class="layui-btn layui-btn layui-btn-xs data-count-edit" lay-event="complete" data="{{d.id}}" >完成</a></div>
                {{#  } }}
                {{#  if(d.order_status < 3){ }}
                <div class="detailContent" style="margin-bottom: 2px"><a class="layui-btn layui-btn-warm layui-btn-xs data-count-edit" lay-event="refund" data="{{d.id}}" >退款</a></div>
                {{#  } }}
            </div>
        </div>
</script>
<script src="/static/lib/layui-v2.7.6/layui.js" charset="utf-8"></script>
<script src="/static/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
    layui.use(['form', 'table','laydate','soulTable'], function () {
        var $ = layui.jquery,
            form = layui.form,
            laydate = layui.laydate,
            table = layui.table,
            soulTable = layui.soulTable;

        var mytable = table.render({
            elem: '#currentTableId',
            url: '/order/index?list=all',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                // {width: 45,fixed:'true', collapse: true, icon: ['layui-icon layui-icon-triangle-r', 'layui-icon layui-icon-triangle-d'], children: '#expandAll', childWidth: 'full'},
                {field: 'serial_num', width: 69, title: '编号', align: 'left', sort: true, fixed: 'true', collapse: true,
                    icon: ['layui-icon layui-icon-triangle-r', 'layui-icon layui-icon-triangle-d'],
                    children: '#expandAll',
                    childWidth: 'full'
                },
                {field: 'send_time', width: 159, title: '配送时间', align: 'left', sort: true, fixed: 'true',
                    templet: function (d) {
                        if (d.start_time == d.end_time) {
                            return d.start_time;
                        } else {
                            return d.send_time;
                        }
                    }
                },
                // {title: '#', width: 50,fixed:'true', collapse: true, icon: ['layui-icon layui-icon-triangle-r', 'layui-icon layui-icon-triangle-d'], children: '#expandAll', childWidth: 'full'},

                {field: 'img', title: '花束', width: 150, align: 'left', fixed: 'true', templet: function (d) {
                        return '<span><img  src="/img' + (d.img.file_path == "/" ? "":d.img.file_path) + '/' +d.img.file_name + '" onclick="showimg(this)" id="driimg" style="display:inline-block;width: 20px;height: 25px;margin-right: 10px;"/></span><span>' + d.flower_name + '</span>';
                    }
                },
                // {field: 'flower_name', width: 150, title: '花束名',align:'center',fixed:'true',edit: 'text'},
                {field: 'card', width: 69, title: '卡片', align: 'center', sort: true, fixed: 'true', event: 'showCardContent', style: 'cursor: pointer;', templet: function (d) {
                        if (d.card == 0) {
                            return `<i class="layui-icon" style="font-size: 20px; color: #dedada;">✖</i>`;
                        } else {
                            return `<i class="layui-icon" style="font-size: 20px; color: #51d021;">✔</i>`;
                        }
                    }
                },
                {field: 'send_type', width: 69, title: '配送', align: 'left', sort: true, fixed: 'true',
                    templet: function (d) {
                        if (d.send_type == 0) {
                            return `<span style="color: #51d021;">自取</span>`;
                        } else if (d.send_type == 1) {
                            return `<span style="color: #ffbf18;">自配</span>`;
                        } else if (d.send_type == 2) {
                            return `<span style="color: #f6092c;">达达</span>`;
                        }else if (d.send_type == 3) {
                            return `<span style="color: #d90ac4;">专车</span>`;
                        }
                    }
                }, //0.自配 1.达达 2.自取 3.专车
                {field: 'order_status', width: 70, title: '状态', align: 'left', sort: true, fixed: 'true',
                    templet: function (d) {
                        if (d.order_status == 0) {
                            return `<span style="color: #f6092c;"  id="test_` + d.id + `" class="stps" onmouseover="showTips(` + d.id + `,'` + d.created_at + `')" onmouseleave="closeTips()">未处理</span>`;
                        } else if (d.order_status == 1) {
                            return `<span style="color: #ffbf18;"  id="test_` + d.id + `" class="stps" onmouseover="showTips(` + d.id + `,'` + d.deal_time + `')" onmouseleave="closeTips();">待配送</span>`;
                        } else if (d.order_status == 2) {
                            return `<span style="color: #51d021;" id="test_` + d.id + `"  class="stps" onmouseover="showTips(` + d.id + `,'` + d.complete_time + `')" onmouseleave="closeTips();">已完成</span>`;
                        } else if (d.order_status == 3) {
                            return `<span style="color: #adabab;"  id="test_` + d.id + `" class="stps" onmouseover="showTips(` + d.id + `,'` + d.refund_time + `')" onmouseleave='closeTips();'>退款</span>`;
                        }
                    }
                },
                {field: 'address', width: 270, title: '地址', align: 'center', edit: 'text'},
                {field: 'mobile', width: 104, title: '手机号', align: 'center', edit: 'text'},
                {field: 'name', width: 70, title: '姓名', align: 'center', edit: 'text'},
                {field: 'card_content', width: 100, title: '卡片内容', align: 'center', edit: 'text'},
                {field: 'vx', width: 99, title: '微信', align: 'center', edit: 'text'},
                {field: 'order_type', width: 70, title: '类型', align: 'center', sort: true, templet: function (d) {
                        if (d.order_type == 0) {
                            return `<span style="color: #51d021;">微信</span>`;
                        } else if (d.order_type == 1) {
                            return `<span style="color: #ffbf18;">门店</span>`;
                        } else if (d.order_type == 2) {
                            return `<span style="color: #ffbf18;">美团</span>`;
                        } else if (d.order_type == 3) {
                            return `<span style="color: #3e8fea;">饿了么</span>`;
                        } else if (d.order_type == 4) {
                            return `<span style="color: #e59748;">抖音</span>`;
                        } else if (d.order_type == 5) {
                            return `<span style="color: #21d0d0;">高德</span>`;
                        }
                    }
                }, //0.线下 1.美团 2.饿了么 3.抖音 4.高德
                {field: 'order_price', width: 69, title: '价格', align: 'center', sort: true, edit: 'number'},
                {field: 'send_price', width: 81, title: '配送费', align: 'center', sort: true, edit: 'number'},
                {field: 'offline_verify', width: 69, title: '核销', align: 'center', sort: true,
                    templet: function (d) {
                        if (d.offline_verify == 0) {
                            return `<span style="color: #3e8fea;">否</span>`;
                        } else if (d.offline_verify == 1) {
                            return `<span style="color: #f6092c;">是</span>`;
                        }
                    }
                }, //0.否 1是
                {title: '操作', minWidth: 66, toolbar: '#currentTableBar', align: "center", fixed: 'right'}
            ]],
            done: function () {    // soulTable专用重渲染
                soulTable.render(this)
            },
            // autoColumnWidth: {  //自适应列宽
            //     init: true
            // },
            overflow: {   //超长字段内容鼠标悬停展开
                type: 'tips'
                // ,hoverTime: 500 // 悬停时间，单位ms, 悬停 hoverTime 后才会显示，默认为 0
                // ,color: 'black' // 字体颜色
                // ,bgColor: 'white' // 背景色
            },
            limits: [10, 15, 20, 25, 50, 100], //分页size列表
            limit: 15,  //分页size
            page: true,   //开启分页
            skin: 'line',  //表格风格
            even: false, //开启隔行背景
            size: 'sm' //小尺寸的表格
        });

        //渲染下拉
        $.ajax({
            url: "/config/getConfigByKey",
            type: 'post',
            data:{"key":"holiday_type"},
            contentType: "application/x-www-form-urlencoded; charset=UTF-8",
            async: false,
            success: function (ret) {
                var date = new Date() // 获取时间
                var year = date.getFullYear() // 获取年
                $("#year").val(year)
                $("#holiday_type").val(ret.data)
                form.render('select');
                // layui.form.render('select')
            },
            error: function (xhr, textstatus, thrown) {
                layer.msg('操作失败');
            }
        });

        //监听表格排序事件，修复soulTable因排序事件导致子表格箭头失效问题
        table.on('sort(currentTableFilter)', function (obj) { //注：sort 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            //重新给下列属性赋值，不然soulTable报错
            this.cols = mytable.config.cols
            this.elem = mytable.config.elem
            this.id = mytable.config.id
            soulTable.render(this)
        });
        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            // layer.alert(result, {
            //     title: '最终的搜索信息'
            // });

            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');

            return false;
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '添加订单',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/static/page/order/add.html',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            } else if (obj.event === 'edit') {
                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                var index = layer.open({
                    title: '编辑订单',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/static/page/order/edit.html?id=' + data[0].id,
                    // success: function (layero,index) {
                    //     //表单初始赋值
                    //    var body = layer.getChildFrame('body',index);
                    //     var iframeWin = layero.find('iframe')[0].contentWindow;
                    //     body.find("input[name='id']").val(data.id)
                    //     iframeWin.layui.form.render();
                    // }
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            } else if (obj.event === 'paidan') {  // 监听删除操作
                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            }
        });
        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            console.log(data.id)
            if (obj.event === 'edit') {
                var index = layer.open({
                    title: '编辑订单',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/static/page/order/edit.html?id=' + data.id,
                    // success: function (layero,index) {
                    //     //表单初始赋值
                    //    var body = layer.getChildFrame('body',index);
                    //     var iframeWin = layero.find('iframe')[0].contentWindow;
                    //     body.find("input[name='id']").val(data.id)
                    //     iframeWin.layui.form.render();
                    // }
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'delete') {
                layer.confirm('真的删除行么', function (index) {
                    obj.del();
                    layer.close(index);
                });
            } else if (obj.event === 'showCardContent') {
                if (data.card == 0) {
                    return false
                }
                layer.prompt({
                    formType: 2
                    , title: ' 编号[' + data.serial_num + '] 的卡片内容'
                    , value: data.card_content
                }, function (value, index) {
                    layer.close(index);

                    //这里一般是发送修改的Ajax请求
                    $.ajax({
                        url: "/order/edit",
                        type: 'post',
                        contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                        data: JSON.stringify({id: data.id, card_content: value}),
                        async: false,
                        success: function (ret) {
                            layer.msg("操作成功");
                        },
                        error: function (xhr, textstatus, thrown) {
                            layer.msg('操作失败');
                        }
                    });
                    //同步更新表格和缓存对应的值
                    obj.update({
                        card_content: value
                    });
                });
            } else if (obj.event === 'changeSendTime') {
                layer.prompt({
                    formType: 2
                    , title: '修改 ID 为 [' + data.id + '] 的用户签名'
                    , value: data.send_time
                }, function (value, index) {
                    layer.close(index);

                    //这里一般是发送修改的Ajax请求

                    //同步更新表格和缓存对应的值
                    obj.update({
                        send_time: value
                    });
                });
            } else if (obj.event === 'deal') {
                var time = getNowFormatTime()
                var id = parseInt(this.attributes.data.value)
                layer.confirm('确定 <b style="color:#3e8fea;font-size: large;">排单</b> ?', {title: '提示'}, function (index) {
                    $.ajax({
                        url: "/order/edit",
                        type: 'post',
                        contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                        data: JSON.stringify({id: id, deal_time: time}),
                        async: false,
                        success: function (ret) {
                            layer.msg("操作成功");
                            table.reload('currentTableId', {page: {curr: 1}});
                        },
                        error: function (xhr, textstatus, thrown) {
                            layer.msg('操作失败');
                        }
                    });
                    layer.close(index);
                });
            } else if (obj.event === 'complete') {
                var time = getNowFormatTime()
                var id = parseInt(this.attributes.data.value)
                layer.confirm('确定 <b style="color:#009688;font-size: large;">完成</b> ?', {title: '提示'}, function (index) {
                    $.ajax({
                        url: "/order/edit",
                        type: 'post',
                        contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                        data: JSON.stringify({id: id, complete_time: time}),
                        async: false,
                        success: function (ret) {
                            layer.msg("操作成功");
                            table.reload('currentTableId', {page: {curr: 1}});
                        },
                        error: function (xhr, textstatus, thrown) {
                            layer.msg('操作失败');
                        }
                    });
                    layer.close(index);
                });
            } else if (obj.event === 'refund') {
                var time = getNowFormatTime()
                var id = parseInt(this.attributes.data.value)
                layer.confirm('确定 <b style="color:#ffb800;font-size: large;">退款</b> ?', {title: '提示'}, function (index) {
                    $.ajax({
                        url: "/order/edit",
                        type: 'post',
                        contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                        data: JSON.stringify({id: id, refund_time: time}),
                        async: false,
                        success: function (ret) {
                            layer.msg("操作成功");
                            table.reload('currentTableId', {page: {curr: 1}});
                        },
                        error: function (xhr, textstatus, thrown) {
                            layer.msg('操作失败');
                        }
                    });
                    layer.close(index);
                });
            }
        });
        //监听单元格编辑
        table.on('edit(currentTableFilter)', function (obj) {
            var value = obj.value //得到修改后的值
                , data = obj.data //得到所在行所有键值
                , field = obj.field; //得到字段
            // layer.msg('[ID: ' + data.id + '] ' + field + ' 字段更改为：' + value);
            $.ajax({
                url: "/order/edit",
                type: 'post',
                contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                data: JSON.stringify(data),
                async: false,
                success: function (ret) {
                    // var msg = ret.msg || "操作成功"
                    layer.msg("操作成功");
                },
                error: function (xhr, textstatus, thrown) {
                    layer.msg('操作失败');
                }
            });
        });
        //日期时间范围
        laydate.render({
            elem: '#test10'
            , type: 'datetime'
            , range: true
        });
        $('.stps').on('mouseover', function () {

            layer.tips('aaaa', this, {

                tips: [3, "#4794ec"]

            });
        });
    });
    function showimg(t){
        layer.open({
            type:1,
            title:false,
            closeBtn:0,
            area:'400px',
            skin:'layui-layer-nobg',
            shadeClose:true,
            content:'<img style="display: inline-block;width: 100%;height: 100%;" src="'+t.src+'">'
        });
    }
    function getNowFormatTime() {
        let nowDate = new Date()
        var year = nowDate.getFullYear();
        var month = ('0'+(nowDate.getMonth()+1)).slice(-2);
        var date =('0'+(nowDate.getDate())).slice(-2);
        var hour = nowDate.getHours();
        var minute = nowDate.getMinutes();
        var second = nowDate.getSeconds();
        return year+'-'+month+'-'+date+' '+hour+':'+minute+':'+second
    }
    var tipsVal;
    function showTips(id,tag) {
        tipsVal= layer.tips(tag, "#test_"+id,{tips:[2,"#009688"]});
    }
    function closeTips() {//关闭显示的信息
        layer.close(tipsVal);
    }
</script>

</body>
</html>